package com.liao.r2dbc.controller;

import com.liao.r2dbc.dao.UserDao;
import com.liao.r2dbc.pojo.TbUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
public class R2DBCController {

    @Autowired
    private UserDao userDao;

    @RequestMapping(value = "/find/{id}")
    private Mono<TbUser> findUser(@PathVariable("id") Integer id){
        System.out.println("廖文龙");
        return userDao.findById(id);
    }

    @RequestMapping(value = "/find")
    private Flux<TbUser> findAllUser(){
        return userDao.myFindAll();
    }

    @RequestMapping(value = "/find/between/{start}/{end}")
    private Flux<TbUser> findUser(@PathVariable(value = "start")Integer start,@PathVariable(value = "end") Integer end){
        return userDao.findByIdBetween(start,end);
    }

    @RequestMapping(value = "/find/annotation/{id}")
    private Flux<TbUser> findUser1(@PathVariable(value = "id") Integer id){
        return userDao.myFindAllById(id);
    }
}
